package com.jacky.me.jnidemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.jacky.me.jnidemo.calljni.CLoadJMethod;
import com.jacky.me.jnidemo.calljni.LoadCMethod;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    LoadCMethod mLoadCMethod;
    private CLoadJMethod mCLoadJMethod;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        mLoadCMethod = new LoadCMethod();
        mCLoadJMethod = new CLoadJMethod();
    }

    @OnClick({R.id.c_sample_text, R.id.c_add, R.id.c_joinstring, R.id.c_array, R.id.c_call_java_code_empty_method
            , R.id.c_call_java_code_args_method, R.id.c_call_java_code_arg_string_method, R.id.c_call_java_code_arg_static_method
            , R.id.c_call_java_code_empty_method2, R.id.sound_activity})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.c_sample_text:
                Toast.makeText(this, mLoadCMethod.stringFromJNI(), Toast.LENGTH_LONG).show();
                break;
            case R.id.c_add:
                Toast.makeText(this, "3+9=" + mLoadCMethod.add(3, 9), Toast.LENGTH_LONG).show();
                break;
            case R.id.c_joinstring:
                Toast.makeText(this, "c拼接字符串:" + mLoadCMethod.jointHelloToJstring("中国 cny "), Toast.LENGTH_LONG).show();
                break;
            case R.id.c_array:
                int[] arr = new int[]{1, 2, 3, 4, 5};
                mLoadCMethod.modifyIntArrayValue(arr);
                for (int i : arr) {
                    Log.d(TAG, "onViewClicked: i=" + i);
                }
                break;
            case R.id.c_call_java_code_empty_method:
                mCLoadJMethod.callMethod1();
                break;
            case R.id.c_call_java_code_args_method:
                mCLoadJMethod.callMethod2();
                break;
            case R.id.c_call_java_code_arg_string_method:
                mCLoadJMethod.callMethod3();
                break;
            case R.id.c_call_java_code_empty_method2:
                mCLoadJMethod.callMethod4();
                break;
            case R.id.c_call_java_code_arg_static_method:
                mCLoadJMethod.callMethod5();
                break;
            case R.id.sound_activity:
                Intent intent = new Intent(this, SoundActivity.class);
                startActivity(intent);
                break;
        }
    }
}
